package cn.wolfcode.crm.util;

import cn.wolfcode.crm.domain.Menu;

import java.util.Iterator;
import java.util.List;

//菜单的工具类
public class MenuUtil {

    public static final String MENUS_IN_SESSION = "menus_in_session";
    //过滤出当前用户的菜单id值
    public static void filterMenu(List<Menu> allMenus, List<Long> ids) {

        if(allMenus == null || ids == null){
            return;
        }

        //此种设计涉及到边跌带边删除
        //获取菜单的迭代器
        Iterator<Menu> it = allMenus.iterator();
        while(it.hasNext()){

            Menu menu = it.next();
            if(!ids.contains(menu.getId())){
                it.remove();
            }else{

                //获取取该菜单的子类
                List<Menu> children = menu.getChildren();
                filterMenu(children,ids);
            }


        }


    }
}
